
import textwrap
import tornado.web

import tornado.httpserver #http服务端
import tornado.ioloop
import tornado.options #选项



from tornado.options import define#定义,options
                        #指定的端口的登录（8000）数字类型整形
define('port',default=8000,help='run on the giver port',type=int)


#主函数tonado.web.requestHandler请求处理器
class IndexHandler(tornado.web.RequestHandler):
    def get(self,input):
        #切片
        self.write(input[::-1])

class WrapHandler(tornado.web.RequestHandler):
    def post(self):
        text=self.get_argument('text')
        width=self.get_argument('width',3000)#宽度
        self.write(textwrap.fill(text,int(width)))



if __name__ == '__main__':
    tornado.options.parse_command_line()
    app=tornado.web.Application(handlers=[
        #reverse反转
        (r'/reverse/(\w+)',IndexHandler),
        (r'wrap',WrapHandler)

    ])

    http_server=tornado.httpserver.HTTPServer(app)
    print('OK' + '欢迎使用')
    http_server.listen(8000)
    tornado.ioloop.IOLoop.instance().start()
